<?php
//call it when PDS is received the file
require_once 'TVB/VideoInfrastructure/Server/requires.php';

function vidistributionCompleteBySourceId($source_id,$returnstatus,$export_id) {

		$rf = VideoInfrastructure::GetWritableRecordFactory();
					// search old octoshape distribution record
				$octodistribution_entry_list = $rf->find('DistributionOcto', 'export_id=? AND source_id = ?',
			    array($export_id, $source_id)
		        );

			if ($octodistribution_entry_list) {
		

					$octomod_entry = array_shift($octodistribution_entry_list);
					$octomod_entry->confirm_time = date('Y-m-d H:i:s');
					$octomod_entry->pms_status = $returnstatus;


					// save
					$ret = $rf->save_by_fields($octomod_entry, array('export_id','source_id'));		
					if (!$ret) {
					error_log("ERROR CLASS:" . __CLASS__ . ", FUNCTION: " . __FUNCTION__ . ", LINE: " . __LINE__);
					error_log("ERROR - Update VI Distribution Complete record FAILS");
					error_log("Parameters: " . var_export($octomod_entry, TRUE));
				     }
 
		//		      

			}else{
				error_log("ERROR CLASS:" . __CLASS__ . ", FUNCTION: " . __FUNCTION__ . ", LINE: " . __LINE__);
				error_log("call back ID from export_id={$export_id} source_id={$source_id} is not correct ");

			}		
					

		
}			
$source_id = isset($_REQUEST['source_id']) ? $_REQUEST['source_id'] : 3819;
$returnstatus = isset($_REQUEST['returnstatus']) ? $_REQUEST['returnstatus'] : 1;
$export_id = isset($_REQUEST['export_id']) ? $_REQUEST['export_id'] : 206;
vidistributionCompleteBySourceId($source_id,$returnstatus,$export_id);
?>